local skel = fk.CreateSkill {
  name = "emo__shangzhan",
}

Fk:loadTranslationTable{
  ["emo__shangzhan"] = "赏战",
  [":emo__shangzhan"] = "出牌阶段限一次，你可以令一名角色使用一张伤害牌，你与其各获得受到此牌伤害的角色随机一张牌。",

  ["#emo__shangzhan"] = "赏战:令一名角色使用一张伤害牌",
  ["#emo__shangzhan-use"] = "赏战:你可以使用一张伤害牌",
}

skel:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#emo__shangzhan",
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local names = {}
    for name, card in pairs(Fk.all_card_types) do
      if card.is_damage_card then
        table.insert(names, name)
      end
    end
    local use = room:askToUseCard(to, {
      skill_name = skel.name, prompt = "#emo__shangzhan-use", extra_data = {bypass_times = true},
      pattern = ".|.|.|.|".. table.concat(names, ",")
    })
    if not use then return end
    use.extraUse = true
    room:useCard(use)
    if use.damageDealt == nil then return end
    local victims = {}
    for victim, _ in pairs(use.damageDealt) do
      if victim:isAlive() then
        table.insert(victims, victim)
      end
    end
    if #victims == 0 then return end
    local drawers = {player}
    table.insertIfNeed(drawers, to)
    for _, from in ipairs(drawers) do
      if not from.dead then
        local targets = table.filter(victims, function(p) return not p:isNude() end)
        if #targets > 0 then
          local cid = table.random(table.random(targets):getCardIds("he"))
          room:obtainCard(from, cid, true, fk.ReasonPrey, from, skel.name)
        end
      end
    end
  end,
})

return skel
